/* Copyright 2021 Kerim Yalcin
**
**   Licensed under the Apache License, Version 2.0 (the "License");
**   you may not use this file except in compliance with the License.
**   You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
**   Unless required by applicable law or agreed to in writing, software
**   distributed under the License is distributed on an "AS IS" BASIS,
**   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**   See the License for the specific language governing permissions and
**   limitations under the License.
*/

#ifndef AGX_ACCESSTOKEN_HEADER
#define AGX_ACCESSTOKEN_HEADER

#include <windows.h>
#include "../Base.hpp"

namespace Agx {

class AccessToken : public Base {
    private:
        HANDLE mToken;
        HANDLE mProcess;
        HANDLE mThread;

        TOKEN_INFORMATION_CLASS mInformationType;
        DWORD mAccess_desired;
        bool mQueryHasSuccess;

        TOKEN_USER* mUserAccounts;

    public:
        AccessToken();
        ~AccessToken();

        AccessToken& free();
        AccessToken& init();

        AccessToken& set_Process(const HANDLE& pProcess);
        AccessToken& set_Thread(const HANDLE& pThread);

        AccessToken& enable_Access_desired_AdjustDefault();
        AccessToken& enable_Access_desired_AdjustGroups();
        AccessToken& enable_Access_desired_AdjustPrivileges();
        AccessToken& enable_Access_desired_AdjustSessionID();
        AccessToken& enable_Access_desired_AssignPrimary();
        AccessToken& enable_Access_desired_Duplicate();
        AccessToken& enable_Access_desired_Excute();
        AccessToken& enable_Access_desired_Impersonate();
        AccessToken& enable_Access_desired_Query();
        AccessToken& enable_Access_desired_QuerySource();
        AccessToken& enable_Access_desired_Read();
        AccessToken& enable_Access_desired_Write();
        AccessToken& enable_Access_desired_All();

        AccessToken& disable_Access_desired_AdjustDefault();
        AccessToken& disable_Access_desired_AdjustGroups();
        AccessToken& disable_Access_desired_AdjustPrivileges();
        AccessToken& disable_Access_desired_AdjustSessionID();
        AccessToken& disable_Access_desired_AssignPrimary();
        AccessToken& disable_Access_desired_Duplicate();
        AccessToken& disable_Access_desired_Excute();
        AccessToken& disable_Access_desired_Impersonate();
        AccessToken& disable_Access_desired_Query();
        AccessToken& disable_Access_desired_QuerySource();
        AccessToken& disable_Access_desired_Read();
        AccessToken& disable_Access_desired_Write();
        AccessToken& disable_Access_desired_All();

        AccessToken& set_TokenInformationType_toUserAccount();
        AccessToken& set_TokenInformationType_toGroupAccount();
        AccessToken& set_TokenInformationType_toPrivileges();
        AccessToken& set_TokenInformationType_toOwnerSecurityIdentifier();
        const TOKEN_INFORMATION_CLASS& get_TokenInformationType() const;

        AccessToken& query_TokenInformation();
        AccessToken& query_ProcessToken();
        const bool& has_Query_success() const;
};

}

#endif